import request from "@/utils/http";
import type { LoginData, LoginResult } from "./types";
import type { UserInfo } from '@/types/member'
/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): Promise<Result<LoginResult>> {
  // const formData = new FormData();
  // formData.append("username", data.username);
  // formData.append("password", data.password);
  return request<LoginResult>({
    url: "/auth/login",
    method: "POST",
    data: data,
    header: {
      "Content-Type": "application/x-www-form-urlencoded",
      // Authorization: "Basic bWFsbC1hZG1pbjoxMjM0NTY=", // 客户端信息Base64明文：file-sys:123456
    },
  });
}

export function getUserInfoApi():  Promise<Result<UserInfo>>{
  return request<UserInfo>({
    url: "/users/me",
    method: "GET",
  })
}

/**
 * 注销API
 */
export function logoutApi() {
  return request({
    url: "/auth/logout",
    method: "DELETE",
  });
}


